package cn.tedu.carehome.foundation.config;


import cn.tedu.carehome.foundation.mybatis.InsertUpdateTimeInterceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import java.util.List;
import javax.annotation.PostConstruct;

@Configuration
@MapperScan("cn.tedu.carehome.foundation.mapper")
public class MybatisConfiguration {
    @Autowired
    private List<SqlSessionFactory> sqlSessionFactorys;

    @PostConstruct
    public  void setSqlSessionFactory()
    {
        InsertUpdateTimeInterceptor insertUpdateTimeInterceptor = new InsertUpdateTimeInterceptor();
        for (SqlSessionFactory sqlSessionFactory:sqlSessionFactorys) {
          sqlSessionFactory.getConfiguration().addInterceptor(insertUpdateTimeInterceptor);
        }
    }

}
